package com.ybg.ebs_memory.data;

import java.util.HashMap;
import java.util.Map;

public class Customer {
    private String username;
    private String password;
    private float balance;
    private Map<Product,Integer> cart;

    public Customer(String username, String password, float balance) {
        this.username = username;
        this.password = password;
        this.balance = balance;
        this.cart = new HashMap<>();
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public float getBalance() {
        return balance;
    }

    public void setBalance(float balance) {
        this.balance += balance;
    }

    public void pay(float pay){
        this.balance -= pay;
    }

    public Map<Product, Integer> getCart() {
        return cart;
    }

    public void setCart(Product product,int productCount) {
        int count = this.cart.containsKey(product) ? this.cart.get(product) : 0;
        this.cart.put(product,productCount+count);
    }

    public void showLine(){
        System.out.println(String.format("%s\t******\t%.2f\t%d",
                username,balance,cart.size()));
    }

    public void showMe(){
        System.out.println(this);
    }

    @Override
    public String toString() {
        return String.format("账号：%s\n密码：%s\n余额：%.2f（元）\n购物车内商品：%d（件）"
                ,username,password,balance,cart.size());
    }
}
